unit Main;

{if fsScript1.FindLocal('showparam2')<>nil then
begin
  ShowMessage('true');
end else
begin
  ShowMessage('false');
end;}

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, RzPanel, RzSplit, fs_iinterpreter, fs_ipascal,
  StdCtrls, RzEdit, RzButton,Class_KzDebug;

type
  TForm1 = class(TForm)
    fsPascal1: TfsPascal;
    fsScript1: TfsScript;
    RzSplitter1: TRzSplitter;
    Memo_1: TRzMemo;
    Tool_1: TRzToolbar;
    Btnx_1: TRzToolButton;
    Btnx_2: TRzToolButton;
    Btnx_3: TRzToolButton;
    Btnx_4: TRzToolButton;
    procedure FormShow(Sender: TObject);
    procedure Btnx_1Click(Sender: TObject);
    procedure Btnx_2Click(Sender: TObject);
    function fsScript1GetVarValue(VarName: String; VarTyp: TfsVarType;
      OldValue: Variant): Variant;
    procedure Btnx_3Click(Sender: TObject);
    procedure Btnx_4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
begin
  RzSplitter1.Percent:=30;
end;

procedure TForm1.Btnx_1Click(Sender: TObject);
begin
  fsScript1.Clear;
  fsScript1.Lines:=Memo_1.Lines;
  fsScript1.Parent:=fsGlobalUnit;

  if fsScript1.Compile then
  begin
    //fsScript1.Execute;
    fsScript1.CallFunction('showmsg','');
  end else
  begin
    ShowMessage(fsScript1.ErrorMsg);
  end;    
end;

procedure TForm1.Btnx_2Click(Sender: TObject);
begin
  fsScript1.Clear;
  fsScript1.Lines:=Memo_1.Lines;
  fsScript1.Parent:=fsGlobalUnit;

  fsScript1.AddVariable('param1','string','helloworld.script.');
  fsScript1.AddVariable('param2','string','<none>');
  if fsScript1.Compile then
  begin
    //fsScript1.Execute;
    fsScript1.CallFunction('showparam1','');
  end else
  begin
    ShowMessage(fsScript1.ErrorMsg);
  end;
end;

function TForm1.fsScript1GetVarValue(VarName: String; VarTyp: TfsVarType;
  OldValue: Variant): Variant;
begin
  if VarName='param1' then
  begin
    Result:=5000;
  end else
  if VarName='[1]' then
  begin
    Result:=1;
  end else
  if VarName='[2]' then
  begin
    Result:=2;
  end;
end;

procedure TForm1.Btnx_3Click(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.Btnx_4Click(Sender: TObject);
var
  DoubA:Extended;
begin
  fsScript1.Clear;
  fsScript1.Lines:=Memo_1.Lines;
  fsScript1.Parent:=fsGlobalUnit;

  fsScript1.AddVariable('param1','extended',2.0);
  fsScript1.AddVariable('param2','extended',1.0);
  if fsScript1.Compile then
  begin
    //fsScript1.Execute;
    //fsScript1.CallFunction('testplus',null);
    DoubA:=fsScript1.CallFunction('showparam2',VarArrayOf([]));
  end else
  begin
    ShowMessage(fsScript1.ErrorMsg);
  end;
end;

end.
